#include <SDL/SDL.h>

#include "GLOBALS.h"
#include "Update.h"
#include "Paint.h"

  // ALL THE PAINTING/DRAWING FUNCTIONS
  
  void paint_all(SDL_Surface *screen_to_draw){
    
    // Lock the screen for drawing
    SDL_LockSurface(screen_to_draw);
    
    // Draw the snake head
    FillRect(sSnake.body[0].cordX*SCREEN_FACTOR, sSnake.body[0].cordY*SCREEN_FACTOR, SCREEN_FACTOR, SCREEN_FACTOR, COLOR_SNAKE_HEAD, screen_to_draw);
    
    // Draw the body parts of the snake
    for(int snake_part=1;snake_part<sSnake.size;snake_part++){
      FillRect((sSnake.body[snake_part].cordX*SCREEN_FACTOR), (sSnake.body[snake_part].cordY*SCREEN_FACTOR), SCREEN_FACTOR, SCREEN_FACTOR, COLOR_SNAKE_BODY, screen_to_draw);
    }
    
    // Draw the piece of cake
    FillRect((sPieceofcake.cordX*SCREEN_FACTOR), (sPieceofcake.cordY*SCREEN_FACTOR), SCREEN_FACTOR, SCREEN_FACTOR, COLOR_POC, screen_to_draw);
    
    // Unlock the surface
    SDL_UnlockSurface(screen_to_draw);
    // Update the entire screen
    SDL_UpdateRect(screen_to_draw, 0, 0, 0, 0);
  }
  
  // Draw a rectangle on the surface
  void FillRect(int x, int y, int w, int h, int color, SDL_Surface *screen_draw) {
    SDL_Rect rect = {x,y,w,h};
    SDL_FillRect(screen_draw, &rect, color);
  }